package cn.relx.org.controller;

import cn.relx.basic.util.AjaxResult;
import cn.relx.basic.util.PageList;
import cn.relx.org.domain.SystemDictionaryDetail;
import cn.relx.org.query.DepartmentQuery;
import cn.relx.org.service.SystemDictionaryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/DictionaryDetail")
public class SystemDictionaryDetailController {
    @Autowired
    private SystemDictionaryDetailService detailService;

    @PostMapping
    public PageList<SystemDictionaryDetail> queryByPage(@RequestBody DepartmentQuery query){
        return detailService.queryByPage(query);
    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        detailService.delete(id);
        return AjaxResult.me().success();
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody SystemDictionaryDetail detail){
        if(detail.getId() == null){
            detailService.add(detail);
        }else {
            detailService.update(detail);
        }
        return AjaxResult.me().success();
    }

    @GetMapping("/{id}")
    public SystemDictionaryDetail findById(@PathVariable("id") Long id){
        return detailService.findById(id);
    }

    @PatchMapping
    public AjaxResult batchDel(@RequestBody List<Long> ids){
        detailService.batchDel(ids);
        return AjaxResult.me().success();
    }
}
